home *** CD-ROM | disk | FTP | other *** search
/ Amiga CD-ROM Collection / Amiga CD-ROM Collection - Auge 4000 and Cactus and Demo Util.iso / auge4000 / 12 / fraktalekarten / enq.c < prev    next >
C/C++ Source or Header  |  1987-05-31  |  10KB  |  287 lines

  1. /* *************************************************************************
  2.  
  3.        The modified code in the appended section was extracted from
  4.  
  5.                      MENUS, REQUESTORS, AND GADGETS 
  6.                                   BY 
  7.                             John T. Draper 
  8.                  A service from the Programmers Network 
  9.                        on the WELL in Sausalito. 
  10.                      Article 408@well and 409@well
  11.                           December 31, 1985
  12.  
  13.   Permission to post this on other networks is granted provided the 
  14. source of this information is included.   The programmers network is 
  15. a non-profit network exchange of programming information.   For more 
  16. information,  mail your requests to: 
  17.  
  18. WELL: crunch orsomewellprogrammerwhosequipmenthasnotbeenseized
  19. BIX:  crunch orsomewellprogrammerwhosequipmenthasnotbeenseized
  20. USENET: ihnp4!ptsfa!well!crunch orsomewellprogrammerwhosequipmenthasnotbeenseized
  21. DELPHI: crunch orsomewellprogrammerwhosequipmenthasnotbeenseized
  22.  
  23.  ************************************************************************* */
  24.  
  25. /*
  26.  * Hacked to make autoEnquirer, a positionable position-tracking requester
  27.  *
  28.  *   Date:        July 11, 1987
  29.  *   Barbarian:   Howard Hull
  30.  *   Implements:  custom requester code from John Draper's gadget tutorial
  31.  *                + blood, sweat, tears, & additions to the explative list...
  32.  */
  33.  
  34. /* **********************************************************
  35.  *
  36.  * ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  37.  * :: When you're a tiger trainer, it's a bad deal when  ::
  38.  * :: the tiger gets your attention by putting a paw in  ::
  39.  * :: your face.  This is not only because tiger paws    ::
  40.  * :: don't smell very good  - it's also because you'll  ::
  41.  * :: shortly begin to wonder what the rest of the tiger ::
  42.  * :: is up to.  With that paw in your face, you can't   ::
  43.  * :: determine what you need to know to decide on what  ::
  44.  * :: ought to be done next.  With tigers, it's much the ::
  45.  * :: same as it is with anything else:  As Will Rogers  ::
  46.  * :: once said, "It ain't what we know that gets us in  ::
  47.  * :: trouble.  It's what we know that ain't so..."      ::
  48.  * ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  49.  *
  50.  *
  51.  * I wrote this thing up because I got tired of moving the requester
  52.  * out of the way so I could see what was going on, and that in turn
  53.  * so that I could then decide what to do with the requester.  As all
  54.  * of you by now know, and as is evident in the net programs, if you
  55.  * make an AutoRequest, you get a requester at 0,0 with no programmable
  56.  * options to reposition it anywhere that you'd rather it be put. (Correct?)
  57.  *
  58.  * Given that the Gadget Editor Boys have not yet released their product
  59.  * (I think they are waiting for John Draper's life to get a little less
  60.  * complicated) I thought I'd put this out in the mean time.  As I'm very
  61.  * much a C programming novice, I'm putting this up for some presumably
  62.  * critical guidance.  Rather than being an example of proper code, I'm
  63.  * certain it contains a number of spectacular boo boos - maybe including
  64.  * some assumptions that would make the whole program completely unnecessary.
  65.  * Just as John said, requesters are a pain in the *ss.  But without a
  66.  * gadget editor, this is the sort of thing that has to be done...
  67.  *
  68.  */
  69.  
  70. #include "atv.h"
  71.  
  72. extern short wleftedge;     /* These are the variables in which we     */
  73. extern short wtopedge;      /* put the first received positions.       */
  74.  
  75. extern struct IntuiText negtext; /* Let the user keep the button names in */
  76. extern struct IntuiText postext; /*  in his stuff, like for AutoRequest */
  77.  
  78. struct Requester req;            /* custom requester structure */ 
  79.  
  80. /*
  81.  * Following is the (empty) Requester stucture template.  It contains a
  82.  * pointer to the host window through the RWindow structure.  (The empty
  83.  * Requester structure was defined just above this comment.  It is not
  84.  * declared, since it gets wiped clean by the InitRequester() call in the
  85.  * user's program.  That call could be moved into this section if the user
  86.  * didn't have to follow through by initializing the structure before it
  87.  * can be used.
  88.  */
  89.  
  90. /* struct Requester req     You'll notice this is info, and not code,
  91.                              as it is commented out
  92. {
  93. struct Requester *OlderRequest;
  94. short LeftEdge, TopEdge;   <-- these are relative to RWindow, so we don't
  95. short Width, Height;            need to adjust them when window is moved.
  96. short RelLeft, RelTop;
  97. struct Gadget *ReqGadget;
  98. struct Border *ReqBorder;
  99. struct IntuiText *ReqText;
  100. unsigned short Flags;
  101. unsigned char BackFill;
  102. struct Layer *ReqLayer;
  103. unsigned char ReqPad1[32];
  104. struct BitMap *ImageBMap;
  105. struct Window *RWindow;    <-- this is the link to the window in which the
  106. unsigned char ReqPad2[36];      requester background is plastered.
  107. }; */
  108.  
  109. /*
  110.  * Following is the RWindow structure containing the LeftEdge - TopEdge
  111.  * definition.  We wish to keep track of these two numbers once they are
  112.  * initialized.  This structure is housed in the user's section.
  113.  */
  114.  
  115. /* struct Window *RWindow     Again, notice that this is a comment
  116. {
  117. struct Window *NextWindow;
  118. short LeftEdge, TopEdge;    <-- NULL when uninitialized, but gets set for us.
  119. short Width, Height;
  120. short MouseY, MouseX;
  121. short MinWidth, MinHeight;
  122. unsigned short MaxWidth, MaxHeight;
  123. unsigned long Flags;
  124. struct Menu *MenuStrip;
  125. unsigned char *Title;
  126. struct Requester *FirstRequest;
  127. struct Requester *DMRequest;
  128. short ReqCount;
  129. struct Screen *WScreen;
  130. struct RastPort *RPort;
  131. unsigned char BorderLeft, BorderTop, BorderRight, BorderBottom;
  132. struct RastPort *BorderRPort;
  133. struct Gadget *FirstGadget;
  134. struct Window *Parent, *Descendant;
  135. ushort *Pointer;
  136. short PtrHeight;
  137. short PtrWidth;
  138. short XOffset, YOffset;
  139. unsigned long IDCMPFlags;
  140. struct MsgPort *UserPort, *WindowPort;
  141. struct IntuiMessage *MessageKey;
  142. unsigned char DetailPen, BlockPen;
  143. struct Image *CheckMark;
  144. unsigned char *ScreenTitle;
  145. short GZZMouseX;
  146. short GZZMouseY;
  147. short GZZWidth;
  148. short GZZHeight;
  149. unsigned char *ExtData;
  150. char *UserData;
  151. struct Layer *WLayer;
  152. struct TextFont *IFont;
  153. }; */
  154.  
  155. short autoEnquire();
  156.  
  157. /***************************************************************************
  158. *              I M P O R T A N T         C O N S T A N T S
  159. ***************************************************************************/
  160.  
  161. #define NL 0
  162.  
  163. #define REDP 3
  164. #define BLKP 2
  165. #define WHTP 1
  166. #define BLUP 0
  167.  
  168. /***************************************************************************
  169.                CUSTOM REQUEST WITH TEXT, BORDERS, AND GADGETS
  170. ***************************************************************************/
  171.  
  172. /* Border for buttons */
  173. SHORT Pairs[] = {
  174.  0, 0,            /* Coordinates relative to button position definition */
  175.  43, 0,
  176.  43, 12,
  177.  0, 12,
  178.  0,  0
  179. };
  180.  
  181. #define NUM_PAIRS 5        /* 5 pairs make a rectangle, start and stop incl */
  182. struct Border butt_border = {
  183.  -1,  -1,
  184.  BLUP, 0, JAM1,
  185.  NUM_PAIRS,
  186.  (SHORT *) Pairs,
  187.  NULL
  188. };
  189.  
  190. /* FALSE BUTTON */
  191. #define ONE_BUTT 1      /** GadgetID used to identify the action ***/
  192. struct Gadget offgad = {
  193.   NULL,
  194.   7, 42,                  /* LeftEdge, TopEdge     */
  195.   42, 11,                 /* Width,  Height        */
  196.   GADGHCOMP,              /* Flag                  */
  197.   RELVERIFY | ENDGADGET,  /* Activation            */
  198.   BOOLGADGET | REQGADGET, /* GadgetType            */
  199.   (APTR)&butt_border,     /* GadgetRender - Border */
  200.   NULL,                   /* SelectRender          */
  201.   &negtext,               /* "OK" text             */
  202.   NL, NL, ONE_BUTT, NL          /* Mut Excl, Spec Info,  */
  203. };
  204.  
  205. /* TRUE BUTTON */
  206. #define TWO_BUTT 2
  207. struct Gadget ongad = {
  208.   &offgad,
  209.   7, 22,                  /* LeftEdge, TopEdge     */
  210.   42, 11,                 /* Width,  Height        */
  211.   GADGHCOMP,              /* Flag                  */
  212.   RELVERIFY | GADGIMMEDIATE,   /* Activation       */
  213.   BOOLGADGET | REQGADGET, /* GadgetType            */
  214.   (APTR)&butt_border,     /* GadgetRender - Border */
  215.   NULL,                   /* SelectRender          */
  216.   &postext,               /* "OK" text             */
  217.   NL, NL, TWO_BUTT, NL    /* Mut Excl, Spec Info,  */
  218. };
  219.  
  220.  
  221. /* Outside Border of Requester */
  222. SHORT ReqPairs[] = {
  223.  3, 3,        /* Coordinates relative to requester sheet top left corner */
  224.  53, 3,
  225.  53, 57,
  226.  3, 57,
  227.  3, 3
  228. };
  229.  
  230. struct Border out_border = {
  231.  -1, -1,
  232.  BLKP, 0, JAM1,
  233.  NUM_PAIRS,
  234.  (SHORT *) ReqPairs,
  235.  NULL
  236. };
  237.  
  238. /***************************************************************************
  239.                    D O   C U S T O M    R E Q U E S T
  240. ***************************************************************************/
  241.  
  242. /*
  243.  * Just as Enquiring minds want to know, Enquiring eyes want to see...
  244.  */
  245.  
  246. autoEnquire()
  247.  
  248.     short looping = TRUE;
  249.     short response = FALSE;
  250.     struct IntuiMessage *mes;
  251.     struct Gadget *gad;           /* Gadget chosen */
  252.     unsigned long class; 
  253.  
  254.     while (looping) 
  255.         { 
  256.         if ((mes = (struct IntuiMessage *)GetMsg(RWindow->UserPort)) == 0L)
  257.             { 
  258.             (VOID) Wait(1L<<RWindow->UserPort->mp_SigBit); 
  259.             continue; 
  260.         } 
  261.         class = mes->Class; 
  262.         gad = (struct Gadget *)mes->IAddress; 
  263.         (VOID) ReplyMsg(mes); 
  264.         if (class == REQCLEAR)
  265.             looping = FALSE; 
  266.         if (class == GADGETDOWN)
  267.             { 
  268.             switch (gad->GadgetID)
  269.                 { 
  270.                 case TWO_BUTT:  response = (short)TWO_BUTT-1;
  271.                                  EndRequest(&req, RWindow);
  272.                                  break; 
  273.                 case ONE_BUTT:  response = (short)ONE_BUTT-1;
  274.                                  EndRequest(&req, RWindow);
  275.                                  break; 
  276.  
  277.                 /* As you can see, adding more buttons would be easy */
  278.             } 
  279.         } 
  280.     } 
  281.     wleftedge = RWindow->LeftEdge;
  282.     wtopedge = RWindow->TopEdge;
  283. return (response);
  284.  
  285.